home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4065 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  41 lines

  1. Path: camelot.ccs.neu.edu!jason
  2. From: jason@ccs.neu.edu (Jason Leatherman)
  3. Newsgroups: comp.lang.c
  4. Subject: Float calculations
  5. Date: 1 Feb 1996 17:22:23 GMT
  6. Organization: College of Computer Science, Northeastern University.
  7. Message-ID: <4eqssf$d9q@camelot.ccs.neu.edu>
  8. NNTP-Posting-Host: alumni.ccs.neu.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.  
  12. Hi,
  13.  
  14.   Check out the results I get when running this simple program on a
  15. Sparc/UNIX system, compiled with gcc:
  16.  
  17. #include <stdio.h>
  18.  
  19. void main()
  20. {
  21.   float a, b;
  22.  
  23.   printf("%0.10f  %0.10f  %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
  24.  
  25.   a = 99974.0;
  26.   b = 50.0;
  27.   printf("%0.10f  %0.10f  %0.10f\n", a, b, a/b);
  28. }
  29.  
  30. The output is:
  31. 99974.0000000000  50.0000000000  1999.4800000000
  32. 99974.0000000000  50.0000000000  1999.4799804688
  33.  
  34.   Why do the divisions produce different results?  This is probably some
  35. simple thing that I've forgotten, but I haven't figured it out yet.  Does
  36. anyone know?  Note that compiling with the -ffloat-store flag didn't make
  37. a difference.
  38.   Thanks for any help,
  39.  
  40. Jason
  41.